import {ElMessage, ElMessageBox} from "element-plus";

const message = {
    info(message, duration = 2000) {
        ElMessage({type:"info", message: message, duration: duration, showClose: true})
    },
    warning(message, duration = 2000) {
        ElMessage({ type:"warning", message: message, duration: duration, showClose: true})
    },
    success(message, duration = 2000) {
        ElMessage({type:"success", message: message, duration: duration, showClose: true})
    },
    error(message, duration = 2000) {
        ElMessage({type:"error", message: message, duration: duration, showClose: true})
    },
    alertInfo(message, title = null, callback=null) {
        if (title) {
            ElMessageBox.alert(message, title, {
                confirmButtonText: 'OK',
                callback: callback,
                type: "info"
            })
        } else {
            ElMessageBox.alert(message, {
                confirmButtonText: 'OK',
                callback: callback,
                type: "info"
            })
        }
    },
    alertWaring(message, title = null, callback=null) {
        if (title) {
            ElMessageBox.alert(message, title, {
                confirmButtonText: 'OK',
                callback: callback,
                type: "warning"
            })
        } else {
            ElMessageBox.alert(message, {
                confirmButtonText: 'OK',
                callback: callback,
                type: "warning"
            })
        }
    },
    alertSuccess(message, title = null, callback=null) {
        if (title) {
            ElMessageBox.alert(message, title, {
                confirmButtonText: 'OK',
                callback: callback,
                type: "success"
            })
        } else {
            ElMessageBox.alert(message, {
                confirmButtonText: 'OK',
                callback: callback,
                type: "success"
            })
        }
    },
    alertError(message, title = null, callback=null) {
        if (title) {
            ElMessageBox.alert(message, title, {
                confirmButtonText: 'OK',
                callback: callback,
                type: "error"
            })
        } else {
            ElMessageBox.alert(message, {
                confirmButtonText: 'OK',
                callback: callback,
                type: "error"
            })
        }
    }
}

export default message